﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Drawing;

namespace Light.Utility.HtmlTable
{
    public class Row
    {
        
        private Alignment _align = Alignment.Default;
        private Color _backColor = Color.Empty;
        private CellCollection _cells = null;
        private FontSetter _fontSetter = null;
        private bool _overrideCellAdornments = false;
        private int _rowIndex = 0;
        private Table _table = null;

        
        public Row()
        {
            this._fontSetter = new FontSetter();
            this._cells = new CellCollection();
            this._cells.Row = this;
        }

        
        public Alignment Align
        {
            get
            {
                if ((this.Table != null) && (this._align == Alignment.Default))
                {
                    return this.Table.Align;
                }
                return this._align;
            }
            set
            {
                if (this.OverrideCellAdornments)
                {
                    for (int i = 0; i < this.Cells.Count; i++)
                    {
                        this.Cells[i].Align = Alignment.Default;
                    }
                }
                this._align = value;
            }
        }

        public Color BackColor
        {
            get
            {
                if ((this.Table != null) && (this._backColor == Color.Empty))
                {
                    if ((this.RowIndex % 2) == 0)
                    {
                        return this.Table.AlternateRowBackColor;
                    }
                    return this.Table.BackColor;
                }
                return this._backColor;
            }
            set
            {
                if (this.OverrideCellAdornments)
                {
                    for (int i = 0; i < this.Cells.Count; i++)
                    {
                        this.Cells[i].BackColor = Color.Empty;
                    }
                }
                this._backColor = value;
            }
        }

        public CellCollection Cells
        {
            get
            {
                return this._cells;
            }
            set
            {
                this._cells = value;
                if (this._cells != null)
                {
                    for (int i = 0; i < this._cells.Count; i++)
                    {
                        this._cells[i].Row = this;
                    }
                }
            }
        }

        public FontSetter FontSetter
        {
            get
            {
                if ((this.Table != null) && this._fontSetter.Equals(FontSetter.Default))
                {
                    this._fontSetter.CopyFrom(this.Table.FontSetter);
                }
                return this._fontSetter;
            }
            set
            {
                if (this.OverrideCellAdornments)
                {
                    for (int i = 0; i < this.Cells.Count; i++)
                    {
                        this.Cells[i].FontSetter = FontSetter.Default;
                    }
                }
                this._fontSetter = value;
            }
        }

        public bool OverrideCellAdornments
        {
            get
            {
                return this._overrideCellAdornments;
            }
            set
            {
                this._overrideCellAdornments = value;
            }
        }

        public int RowIndex
        {
            get
            {
                if ((this.Table != null) && (this._rowIndex == 0))
                {
                    this.Table.SetRowIndex();
                }
                return this._rowIndex;
            }
            set
            {
                this._rowIndex = value;
            }
        }

        public Table Table
        {
            get
            {
                return this._table;
            }
            set
            {
                this._table = value;
            }
        }
    }
}
